package com.miyake.dsp.osa.realinstrument;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Serializable;
import java.util.List;

import com.miyake.realinstrument.MS9740A;

public class SaveData implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = -8274050125623024601L;
	double[] trace;
	int point;
	double center;
	double span;
	String vbw;
	List<Hige> higes;
	double speed;
	String trigger;
	String pointAvg;
	String highDynamic;
	String triggerDelay;
	String resolution;
/*	public SaveData(double[] trace, int point, double center, double span, 
			String vbw, double speed, List<Hige> higes) {
		super();
		this.trace = trace;
		this.point = point;
		this.center = center;
		this.span = span;
		this.vbw = vbw;
		this.higes = higes;
		this.speed = speed;
	}*/
	
	public SaveData(MS9740A ms9740a, double[] trace, double speed) {
		this.speed = speed;
		this.center = Double.valueOf(ms9740a.query("CNT?"));
		this.span = Double.valueOf(ms9740a.query("SPN?"));
		this.vbw = ms9740a.query("VBW?");
		this.trace = trace;
		this.trigger = ms9740a.query("TDL?");
		this.pointAvg = ms9740a.query("AVT?");
		this.highDynamic = ms9740a.query("MDM?");
		this.triggerDelay = ms9740a.query("TDL?");
		this.resolution = ms9740a.query("RES?");
	}
	
	public void toCSV(String filename) {
		try {
			FileWriter writer = new FileWriter(new File(filename));
			for (int i = 0; i < trace.length; i++) {
				writer.write(String.valueOf(trace[i]));
				writer.write("\n");
			}
			writer.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
}
class Hige implements Serializable {
	public Hige(double wavelength, double diff) {
		super();
		this.wavelength = wavelength;
		this.diff = diff;
	}
	double wavelength;
	double diff;
};